package com.controller.admin;

import com.service.admin.AdminCommentService;
import com.service.admin.AdminReportService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class AdminCommentController {
  @Autowired AdminCommentService adminCommentService;
  @Autowired AdminReportService adminReportService;

  /**
   * 获取所有评论数量
   *
   * @return 所有评论数量
   */
  @PostMapping("admin/getAllCommentCount")
  public String getAllCommentCount() {
    int count = adminCommentService.getAllCommentCount();
    return String.valueOf(count);
  }

  /**
   * 获取所有评论信息
   *
   * @param pageSize 页大小
   * @param pageIndex 页索引
   * @return 获取所有评论信息
   */
  @PostMapping("admin/getAllComments")
  public List<Map<String, Object>> getAllComments(
      @RequestParam("pageSize") int pageSize, @RequestParam("pageIndex") int pageIndex) {
    return adminCommentService.getAllComments(pageSize, pageIndex);
  }

  /**
   * 设置评论不合格
   *
   * @param adminName 管理员姓名
   * @param commentId 评论编号
   * @param type 举报类型
   * @param reason 举报原因
   * @param result 处理结果：1为提醒，2为警告，3为取消评论权限
   * @param banDays 禁言天数
   * @param noticeCommentUser 回复模板
   * @return 成功返回1，失败返回0
   */
  @PostMapping("admin/setCommentUnqualified")
  public String setCommentUnqualified(
      @RequestParam("adminName") String adminName,
      @RequestParam("commentId") String commentId,
      @RequestParam("type") String type,
      @RequestParam("reason") String reason,
      @RequestParam("result") int result,
      @RequestParam("banDays") int banDays,
      @RequestParam("noticeCommentUser") String noticeCommentUser) {
    int ret =
        adminReportService.setCommentUnqualified(
            adminName, commentId, type, reason, result, banDays, noticeCommentUser);
    return String.valueOf(ret);
  }
}
